//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
//引用腾讯地图API
var QQMapWX = require('../../common/qqmap-wx-jssdk.js');
var qqmapsdk;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    allGoodsData: [],
    state: '',
    pageIndex: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id
    })
    this.GetGoodListByTypeID();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.GetGoodListByTypeID();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  // 商品列表
  GetGoodListByTypeID: function() {
    var that = this;
    var id = this.data.id;
    var isAsc = this.data.isAsc;
    var pageIndex = this.data.pageIndex;
    var showBy = this.data.showBy;
    var state = this.data.state;
    var allGoodsData = this.data.allGoodsData;
    if (pageIndex == 1) {
      wx.showLoading({
        title: '加载中',
      })
    }
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetGoodListByTypeID&PageSize=10&PageIndex=" + pageIndex + "&typeID=" + id),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          allGoodsData.push(json[i])
        }
        that.setData({
          allGoodsData: allGoodsData,
        })
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading();
        // console.log(allGoodsData);
      }
    })
  },
})